<?php
class editAction extends rareAction{
    public function execute(){
        $id = $this->getGetParam('id',0);
        if($id == 0) forward('news/index');
        $newsDao = new DaoNews();
        $news = $newsDao->getOne("id = '$id'");

		$img = service_image::getOne(service_type::NEWS,$id);
		
		$this->assign('images',array($img));
        $this->assign('news',$news);
		if(!Tool::_getCache('isAdmin')){
			Tool::_setCache('currentID',service_menu::getCurrent('1',service_type::NEWS));
		}
    }
    
	public function executePost(){
		$news = $this->getPostParam('news',array());
		$id = $this->getPostParam('id',0);
		$images = $this->getPostParam('img',array());
		if($id==0) jsonReturn(0,"edit fail!");
		if(empty($news)) jsonReturn(0,'edit fail!');
		$newsDao = new DaoNews();
		$news['isIndex'] = 0;
		// get system date
		$now = date("Y-m-d H:i:s");
		$news['updateTime'] = $now;
		$re = $newsDao->update("id='$id'",$news);
		if(!empty($images)){
			service_image::insert($images,service_type::NEWS,$id);
		}
		if($re){
			jsonReturn(1,'ok');
		}else{
			jsonReturn(0,'fail');
		}
	}
}
?>
